/*
 * CheckListRenderer.java
 *
 * Copyright 2011 Universidad Francisco de Paula Santander (UFPS).
 * Todos los Derechos Reservados.
 * Creado el 2/03/2011, 11:28:17 PM
 */

package com.ufps.cuatro.util.render;

import com.ufps.cuatro.modelo.representacion.componente.Componente;
import com.ufps.cuatro.util.model.MyCheckItemComponente;
import java.awt.Component;

import javax.swing.JCheckBox;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

import com.ufps.cuatro.util.model.MyCheckItemPropertiesClass;

/**
 * <i><b>CheckListRenderer:</b></i> @DefinicionClase
 * @author Carlos A. Torres C. - Dolly E. Guerrero. <https://code.google.com/p/tesis4dor/>
 * @version 1.0 2/03/2011
 * @see ListCellRenderer
 * @see JCheckBox
 */
public class CheckListRenderer extends JCheckBox implements ListCellRenderer{
    private static final long serialVersionUID = -5885279304171212614L;

    /** Constructor por Defecto. 
     *  Crea un nuevo objeto CheckListRenderer 
     */
    public CheckListRenderer() {        
    }

    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean hasFocus){
        try{
            setEnabled(list.isEnabled());
            if(value instanceof MyCheckItemPropertiesClass){
                setSelected(((MyCheckItemPropertiesClass)value).isSelected());
            }
            else if(value instanceof MyCheckItemComponente){
                setSelected(((MyCheckItemComponente)value).isSelected());
            }
            else if(value instanceof Componente){
                setSelected(((Componente)value).isSelected());
            }        
            setFont(list.getFont());
            setBackground(list.getBackground());
            setForeground(list.getForeground());
            setText(value.toString());
            return this;
       }
    catch(java.lang.NullPointerException ex){}
    return null;    
    }
}